{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑机构</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="userAdd" id="userAdd" >
                        <input type="hidden" name="mechanism_id" value="{$info.mechanism_id}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">机构名称：</label>
                            <div class="input-group col-sm-4">
                                <input id="mechanism_name" type="text" class="form-control" name="mechanism_name" value="{$info.mechanism_name}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">联系电话：</label>
                            <div class="input-group col-sm-4">
                                <input id="mechanism_phone" type="text" class="form-control" name="mechanism_phone" value="{$info.mechanism_phone}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">组织地址：</label>
                            <div class="input-group col-sm-4">
                                <input id="mechanism_address" type="text" class="form-control" name="mechanism_address" value="{$info.mechanism_address}">

                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">注册号：</label>
                            <div class="input-group col-sm-4">
                                <input id="mechanism_create_code" type="text" class="form-control" name="mechanism_create_code" value="{$info.mechanism_create_code}">

                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">机构logo：</label>
                            <div class="input-group col-sm-5">
                                <input type="hidden" id="data_photo" name="images" >
                                <div id="imgPicker" style="float:left">选择图片</div>
                                <img id="img_data" height="100px" style="float:left;margin-left: 50px;margin-top: -10px;cursor:pointer;" src="{$info.mechanism_logo}" onclick='imgDisplay(this)'/>
                                <div id="fileList" class="uploader-list" style="float:right"></div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="form-group">
                                <label class="col-sm-3 control-label cyanse" >机构简介：</label>
                                <div class="input-group col-sm-5">
                                    <textarea name="content" class="form-control" rows="3" type="text">{$info.mechanism_intro}</textarea>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label yanse">选择省市区：</label>
                            <div class="col-sm-8 form-group">
                                <div class="input-group">
                                    <span class="input-group-addon">省</span>
                                    <select class="form-control m-b chosen-select search" name="sheng" onchange="area(this,'province')" id="province">
                                        <option value="">---- 所在省 ----</option>
                                        {foreach name="province" item="vo"}
                                        <option value="{$vo.district_id}" {$info.mechanism_sheng==$vo.district_id?'selected':''}>{$vo.district}</option>
                                        {/foreach}
                                    </select>
                                    <span class="input-group-addon">市</span>
                                    <select class="form-control m-b chosen-select search" name="shi" onchange="area(this,'city')" id="city">
                                        <option value="">---- 所在市 ----</option>
                                        {foreach name="city" item="vo"}
                                        <option value="{$vo.district_id}" {$info.mechanism_shi==$vo.district_id?'selected':''}>{$vo.district}</option>
                                        {/foreach}
                                    </select>
                                    <span class="input-group-addon">区</span>
                                    <select class="form-control m-b chosen-select search" name="qu" id="district">
                                        <option value="">---- 所在区 ----</option>
                                        {foreach name="district" item="vo"}
                                        <option value="{$vo.district_id}" {$info.mechanism_qu==$vo.district_id?'selected':''}>{$vo.district}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary btsave" type="submit"><i class="fa fa-save"></i> 修改</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}

<script type="text/javascript" src="__JS__/Crop.js"></script>
<script type="text/javascript">
    wk.upload("{:url('Upload/upload')}",2);


    //百度富文本编辑器
//    var editor = UE.getEditor('myEditor', {
//        initialFrameHeight:450,
//        autoHeight: false,
//        autoHeightEnabled:false,
//        autoFloatEnabled:false
//    });

    $.validator.setDefaults({
        highlight: function(e) {
            $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            $(e).closest(".form-control").css("color","#737373");
        },
        success: function(e) {
            // e.closest(".form-group").removeClass("has-error").addClass("has-success")
            $(e).closest(".form-group").removeClass("has-error");
        },
        errorElement: "span",
        errorPlacement: function(e, r) {
            e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            if(r.is("#groupid")){
                e.appendTo(r.parent());
            }
        },
        errorClass: "help-block m-b-none",
        validClass: "help-block m-b-none"
    }), $().ready(function() {
        var e = "<i class='fa fa-times-circle'></i> ";
        $("#userAdd").validate({
            rules: {
                mechanism_name: {
                    required: !0,
                },
                mechanism_phone: {
                    required: !0,
//                    remote:"{:url('Uuser/checkPhone')}",
                },
                mechanism_address: {
                    required: !0,
                },
                mechanism_code: {
                    required: !0,
                },
                images: {
                    required: !0,
                },
                mechanism_create_code: {
                    required: !0,
                },
                content:{
                    required: !0,
                },
                sheng:{
                    required: !0,
                },
                shi:{
                    required: !0,
                },
                qu:{
                    required: !0,
                }
            },
            messages: {
                user_username: {
                    required: e + "请输入机构名",
                },
                mechanism_phone: {
                    required: e + "请输入联系电话",
                },
                mechanism_address: {
                    required: e + "请输入组织地址",
                },
                mechanism_code: {
                    required: e + "请输入机构代码",
                },
                images: {
                    required: e + "请输选择机构logo",
                },
                mechanism_create_code: {
                    required: e + "请输入注册号",
                },
                content:{
                    required: e + "请输入机构简介",
                },
                sheng:{
                    required: e + "请选择省份",
                },
                shi:{
                    required: e + "请选择城市",
                },
                qu:{
                    required: e + "请选择地区",
                }
            },
            submitHandler: function(form) {
//                $('button').attr('disabled', 'disabled');
                $.ajax({
                    url: "{:url('mechanismEdit')}",
                    type: "post",
                    dataType: "json",
                    data: $("#userAdd").serialize(),
                    success: function (data) {
                        if (data.code == 200) {
                            wk.success(data.msg,1,"{:url('Mechanism/index')}");
                        } else {
                            $('button').removeAttr('disabled');
                            wk.error(data.msg,2,'');
                            return false;
                        }
                    }
                });
            },
        })
    });


    //裁剪后的处理
    $("#sureCut").on("click",function () {
        if ($("#tailoringImg").attr("src") == null ){
            return false;
        }else{
            var cas = $('#tailoringImg').cropper('getCroppedCanvas');//获取被裁剪后的canvas
            var base64url = cas.toDataURL('image/png'); //转换为base64地址形式
            $("#img_data").attr('src',base64url).show();
            $('#data_photo').val(base64url);
            //关闭裁剪框
            $("#myModal").modal('hide');
        }
    });


</script>
</body>
</html>